﻿class cn.eminia.AS2.Util {
	//[置顶]
	// import cn.eminia.AS2.Util
	// 全部不显示 Util.all0(this)
	// 全部显示 Util.all1(this)
	//
	function Util() {
	}
	static function parseFFO(str:String, obj:Object) {
		var obj = (obj == null || obj == undefined) ? {} : obj;
		var arr = str.split(",");
		for (var i = 0; i<arr.length; i++) {
			var oo = arr[i];
			var ss = oo.split(":");
			obj[ss[0]] = toTypeFF(ss[1]);
		}
		return obj;
	}
	static function bg0(mc:MovieClip) {
		var blk = mc.createEmptyMovieClip('temp', 0);
		blk._x = -mc._x;
		blk._y = -mc._y;
		//var cc = (mskSet.color == null) ? 0xFFFFFF : mskSet.color;
		var cc = 0xFFFFFF;
		new cn.eminia.AS2.BLK(mc, {width:Stage.width, height:Stage.height, alpha:100, color:cc});
		blk.temp.useHandCursor = false;
		blk.temp.onRollOver = function() {
		};
	}
	static function chk(scope, id) {
		if (scope.constructor != MovieClip) {
			throw new Error('!! 错，该函数用代理 -> '+id);
		}
	}
	static function toTypeFF(a) {
		if (isNaN(a)) {
			return (a);
		} else {
			return Number(a);
		}
	}
	static function parseFFA(str:String) {
		var arr = str.split(",");
		return arr;
	}
	static function all0(a) {
		for (var i in a) {
			a._visible = false;
		}
	}
	static function all1(a) {
		for (var i in a) {
			a._visible = true;
		}
	}
	static function replace(a, b, c) {
		if (b == '\r' && c == null) {
			if (a.indexOf('\r') == -1) {
				return a;
			} else {
				var arr = a.split('\r');
				var str:String = '';
				for (var i = 0; i<arr.length; i++) {
					str += arr[i]+newline;
				}
				return str;
			}
		} else {
			trace('-> '+a.indexOf(b));
			if (a.indexOf(b) == -1) {
				return a;
			} else {
				var arr = a.split(b);
				var str:String = '';
				for (var i = 0; i<arr.length; i++) {
					str += arr[i]+c;
				}
				return str;
			}
		}
	}
	static function compareArray(a, b):Boolean {
		if (a.length != b.length) {
			return false;
		}
		for (var i = 0; i<a.length; i++) {
			if (a[i] != b[i]) {
				return false;
			}
		}
		return true;
	}
	static function getType(a) {
		if (a.constructor == Number) {
			return 'num';
		} else if (a.constructor == String) {
			return 'str';
		} else if (typeof (a) == 'object') {
			if (a.text == undefined) {
				return 'arr';
			} else {
				return 'tf';
			}
		} else if (a.constructor == MovieClip) {
			if (a.style == 'mix') {
				return 'mix';
			}
			return 'mc';
		}
	}
	static function traceObj(obj) {
		trace('!! '+obj);
		for (var i in obj) {
			trace('!! '+i+' -> '+obj[i]);
		}
	}
	static function orderBy(type, scope):Array {
		var arr:Array = [];
		if (type == '|') {
			for (var i in scope) {
				//if (scope[i] instanceof MovieClip) {
				if (scope[i].constructor == MovieClip) {
					arr.push({mc:scope[i], pos:Math.floor(scope[i]._y)});
				}
			}
		} else {
			for (var i in scope) {
				if (scope[i] instanceof MovieClip) {
					arr.push({mc:scope[i], pos:Math.floor(scope[i]._x)});
				}
			}
		}
		arr.sortOn('pos', Array.NUMERIC);
		//arr.reverse();
		//
		var arr2 = [];
		for (var i = 0; i<arr.length; i++) {
			//trace(arr[i].mc._name+' - '+arr[i].pos)
			arr2.push(arr[i].mc);
		}
		return arr2;
	}
}
